package fgoScript.entity.panel;

import alarm.Alarm;
import alarm.ZLable;
import alarm.ZTextField;
import alarm.imp.ZtextDo;
import aoshiScript.entity.IWuNa;
import com.github.houbb.markdown.toc.core.impl.AtxMarkdownToc;
import com.melloware.jintellitype.JIntellitype;
import commons.entity.CommonModules;
import commons.entity.Constant;
import commons.entity.NativeCp;
import commons.util.MySpringUtil;
import fgoScript.entity.Gudazi;
import fgoScript.entity.BaseZButton;
import fgoScript.entity.Zpanel;
import commons.util.GameUtil;
import commons.util.PropertiesUtil;
import gudaziEx.ClickEXPanel;
import gudaziEx.entity.MyComboBoxUI;
import gudaziEx.entity.MyListCellRenderer;
import gudaziEx.entity.RunningChain;
import gudaziEx.util.ChainUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: Fgo界面框架
 * @author: RENZHEHAO
 * @create: 2019-05-22 03:45
 **/
public class FgoFrame extends JFrame {

	private static final Logger LOGGER = LogManager.getLogger(FgoFrame.class);
    public TrayIcon ti;
	private static final long serialVersionUID = 1L;
	private static FgoFrame f;
	public static FgoFrame instance() {
		if (f == null) {
			f = (FgoFrame) MySpringUtil.getApplicationContext().getBean("fgoFrame");
			return f;
		}else {
			return f;
		}
	}
	private List<Component> cpList = new ArrayList<>();;
	private SetupClickPanel setupClickPanel;
	private SystemPanel systemPanel;
	private ClickEXPanel clickEXPanel;
	private Gudazi gudazi;
	private CommonModules commonModules;
	private final Zpanel centerPanel = new Zpanel();

	public void setGudazi(Gudazi gudazi) {
		this.gudazi = gudazi;
	}

	public void setSetupClickPanel(SetupClickPanel setupClickPanel) {
		this.setupClickPanel = setupClickPanel;
	}

	public void setCommonModules(CommonModules commonModules) {
		this.commonModules = commonModules;
	}

	public void setSystemPanel(SystemPanel systemPanel) {
		this.systemPanel = systemPanel;
	}

	public void setClickEXPanel(ClickEXPanel clickEXPanel) {
		this.clickEXPanel = clickEXPanel;
	}

	private IWuNa wuna;

	public void setWuna(IWuNa wuna) {
		this.wuna = wuna;
	}

	@Override
	public void setVisible(boolean b) {
		super.setVisible(b);
	}
	/**
	 * @Description: 初始化init() 构造函数
	 * @Author: RENZHEHAO
	 * @Date: 2019/5/22
	 */
	public FgoFrame() {
		super();
	}
	private List<BaseZButton> getListFromJsonFile(){
		return null;
	}
	private BaseZButton[] bts = new BaseZButton[35];

	private Map<String, BaseZButton> btsMaps = new HashMap<>();
	private List<Zpanel> pageList = new ArrayList<>();
	private final Zpanel basePanel = new Zpanel();
	private final Zpanel backPanel01 = new Zpanel();
	private final Zpanel pagePanel = new Zpanel();

	public Map<String, BaseZButton> getBtsMaps() {
		return btsMaps;
	}

	private final Zpanel menuPanel = new Zpanel();
	private final Zpanel buttonPanel = new Zpanel();
	private final Zpanel ComboPanel = new Zpanel();
	private final Zpanel southPanel04 = new Zpanel();
	private final Zpanel northPanel = new Zpanel();
	private final Zpanel toolPanel = new Zpanel();
	private final Zpanel alarmPanel = Alarm.instance().getAlarmPanel();
	// 初始化
	public void init() {
		intBts();
		basePanel.setLayout(new BorderLayout());
		backPanel01.setLayout(new BorderLayout());
		centerPanel.setLayout(null);
		toolPanel.setLayout(null);
		buttonPanel.setLayout(new GridLayout(1, 2));
		pagePanel.setLayout(new GridLayout(1, 4));
		menuPanel.setLayout(new GridLayout(1, 2));
		southPanel04.setLayout(new GridLayout(1, 1));
		ComboPanel.setLayout(new GridLayout(1, 1));
		northPanel.setLayout(new GridLayout(1, 3));
		// 添加按钮
		BaseZButton jbTemp;
		int size = bts.length;
		int skillcount = 0;
		int len = 2;


		for (int i = 0; i < size; i++) {
			jbTemp = bts[i];
			if(null==bts[i]){
				continue;
			}
			if(false){


			}else if ("终止".equals(jbTemp.getText())) {
				jbTemp.setText("终止");
				addSouthPanle04(jbTemp);
			}else if ("战斗".equals(jbTemp.getText())) {
				jbTemp.setText(jbTemp.getBattleFlag());
				southPanel04.add(jbTemp);
			}else if ("暂停".equals(jbTemp.getText())) {
				jbTemp.setText("暂停");
				addSouthPanle04(jbTemp);

			}else if ("超时".equals(jbTemp.getText())) {
				jbTemp.setText("超时");
				southPanel04.add(jbTemp);
			}
			else if ("点击设置".equals(jbTemp.getText())) {
				jbTemp.setText("点击设置");
				northPanel.add(jbTemp);
			}
			else if ("清空".equals(jbTemp.getText())) {
				jbTemp.setText("重置");
				northPanel.add(jbTemp);
			}
			else if ("解除激活".equals(jbTemp.getText())) {
				jbTemp.setText("解除激活");
				jbTemp.setVerticalTextPosition(SwingConstants.CENTER);
				menuPanel.add(jbTemp);
			}

			else {
				if ("开启账号".equals(jbTemp.getText())) {
					jbTemp.setBounds(5, 5 + (i * (30+len)), 80, 25+len);
				}  else if (jbTemp.getText().contains("细化战斗")) {
					jbTemp.setBounds(5, 5 + (8 * (30+len)), 105, 25+len);
				} else if (jbTemp.getText().contains("刷EXP")) {
					jbTemp.setBounds(5, 5 + (i * (30+len)), 210, 25+len);
				} else {
					jbTemp.setBounds(5, 5 + (i * (30+len)), 320, 25+len);
				}
				if (jbTemp.getText().contains("自动按键")) {
					jbTemp.setBounds(5, 5 + ((12) * (30+len)), 210, 25+len);
					jbTemp.setAllowRepeat(true);
					toolPanel.add(jbTemp);
				} else if(jbTemp.getText().contains("获取鼠标")){
					jbTemp.setBounds(5, 5 + (11 * (30+len)), 210, 25+len);
					toolPanel.add(jbTemp);
				} else if(jbTemp.getText().contains("S+W")){
					jbTemp.setBounds(220, 5 + (11 * (30+len)), 105, 25+len);
					toolPanel.add(jbTemp);
				} else{
					centerPanel.add(jbTemp);
				}
			}
		}
		//选择账号按钮
		ZTextField zf1 = new ZTextField(new ZtextDo("0", "open_" + NativeCp.getUserName(), Constant.FGO + "/","openAccount"));
		zf1.setBounds(90, 5 + (7 * (30+len)), 30, 25+len);
		centerPanel.add(zf1);


		//app文件名设置
		ZTextField appNameZtext = new ZTextField(new ZtextDo("0", "open_" + NativeCp.getUserName(), Constant.FGO + "/", "appName"));
		appNameZtext.setBounds(125, 5 + (7 * (30+len)), 200, 25+len);
		centerPanel.add(appNameZtext);

		//按键类型按钮
		List<String> changeList = new ArrayList<>();
		changeList.add("左键");
		changeList.add("判断");
		changeList.add("按住");
		jbTemp = BaseZButton.getChangeListButton(changeList,"changeButton_" + NativeCp.getUserName(),"", "clickStrategy", true, true, BaseZButton.pink);
		jbTemp.setBounds(220, 5 + (12 * (30+len)), 50, 25+len);
		toolPanel.add(jbTemp);
		//按键倍率按钮
		ZTextField zf2 = new ZTextField(new ZtextDo("0", "changeButton_" + NativeCp.getUserName(),"", "multiFactor"));
		zf2.setBounds(275, 5 + (12 * (30+len)), 50, 25+len);
		toolPanel.add(zf2);
		//显示背景按钮
		BaseZButton showPicBt = new BaseZButton(null, 0,"显示背景",JIntellitype.MOD_SHIFT, (int) 'P',true, true, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730448L;
			@Override
			public void runMethod() {
				showBackGround(this);
			}
		};
		//切换背景按钮
		BaseZButton changePicBt = new BaseZButton(null, 0,"切换背景",JIntellitype.MOD_SHIFT, (int) 'P',true, true, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730448L;
			@Override
			public void runMethod() {
				String dir = NativeCp.getOneDriveDir() + "\\图片\\桌面背景";

                FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(centerPanel), "选择背景");
				fd.setDirectory(dir);
				fd.setVisible(true);
                fd.setFilenameFilter(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        if (name.contains(".jpg")){
                            return true;
                        }
                        return false;
                    }
                });
				fd.setResizable(true);
				changeBackGroundByPath( fd.getDirectory()+ "\\" + fd.getFile());
                fd.setFile(fd.getDirectory()+ "\\" + fd.getFile());
			}
		};
		//MD文件生成目录按钮
		BaseZButton exportCatalog = new BaseZButton(null, 0,"md目录",JIntellitype.MOD_SHIFT, (int) 'P',true, true, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730848L;
			@Override
			public void runMethod() {

                FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(centerPanel), "选择md文件");
				fd.setVisible(true);
                fd.setFilenameFilter(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        if (name.contains(".md")){
                            return true;
                        }
                        return false;
                    }
                });
				fd.setResizable(true);
				String path = fd.getDirectory()+ "\\" + fd.getFile();
				File tempFile = new File(path);
				if (tempFile.exists()){
					//生成md文件的目录
					AtxMarkdownToc.newInstance().genTocFile(fd.getDirectory()+ "\\" + fd.getFile());
				}
                fd.setFile(fd.getDirectory()+ "\\" + fd.getFile());
			}
		};



		//添加分页按钮
		BaseZButton pageBt01 = new BaseZButton(null, 0,"菜单", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;
			@Override
			public void runMethod() {
				showBackGroundInner(showPicBt);
				showMenuPage(showPicBt);
			}
		};
		BaseZButton pageBt02 = new BaseZButton(null, 0,"窗口按键", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;
			@Override
			public void runMethod() {
				setCenterPanelVisible(false);
				pagePanel.setVisible(false);
				setupClickPanel.setVisible(true);
				toolPanel.setVisible(false);
				menuPanel.setVisible(true);
			}
		};
		BaseZButton pageBt03 = new BaseZButton(null, 0,"FGO", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;
			@Override
			public void runMethod() {
				setCenterPanelVisible(true);
				setupClickPanel.setVisible(false);
				alarmPanel.setVisible(false);
				systemPanel.setVisible(false);
				pagePanel.setVisible(false);
				clickEXPanel.setVisible(false); 
				menuPanel.setVisible(true);
			}
		};
		BaseZButton pageBt04 = new BaseZButton(null, 0,"闹钟", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;
			@Override
			public void runMethod() {
				showAlarmPage();
			}
		};
		BaseZButton pageBt05 = new BaseZButton(null, 0,"系统", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;
			@Override
			public void runMethod() {
				showSystemPage();

			}
		};
		BaseZButton pageBt06 = new BaseZButton(null, 0,"按键EX", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;
			@Override
			public void runMethod() {
				showClickExPage();

			}
		};
		pageBt02.setSkillsStatus(3);
		pageBt03.setSkillsStatus(3);
		pageBt04.setSkillsStatus(3);
		pageBt05.setSkillsStatus(3);
		pageBt06.setSkillsStatus(3);

		exportCatalog.setBounds(220, 5 + (6 * (30+len)), 105, 25+len);

		buttonPanel.setOpaque(false);
		southPanel04.setOpaque(false);
		ComboPanel.setOpaque(false);
		alarmPanel.setOpaque(false);
		northPanel.setOpaque(false);
		pagePanel.setOpaque(false);
		menuPanel.setOpaque(false);

		toolPanel.setOpaque(false);

		alarmPanel.setVisible(true);
		//战斗次数按钮
		ZTextField zf3 = new ZTextField(new ZtextDo("0", "st_" + NativeCp.getUserName(), Constant.FGO + "/","battleCount"));
		zf3.setBounds(115, 5 + (8 * (30+len)), 30, 25+len);
		toolPanel.add(zf3);
		toolPanel.setBounds(0, 0, 335, 518);
		buttonPanel.setBounds(150, 5 + (8 * (30+len)), 177, 25+len);
		ComboPanel.setBounds(5, 5 + (9 * (30+len)), 320, 25+len);
		northPanel.setBounds(5, 5 + (13 * (30+len)), 320, 25+len);
		pagePanel.setBounds(0, 0, 335, 518);
		menuPanel.setBounds(5, 5 + (14 * (30+len)), 320, 25+len);
		backPanel01.setBackground(GameUtil.getBackGroundPreFix((int)(333*1.1), (int)(470*1.1)));
		northPanel.setName("bottomButtons");

		menuPanel.add(pageBt01,0);
		menuPanel.add(showPicBt,1);
		menuPanel.add(changePicBt,2);
		pagePanel.add(pageBt02);
		pagePanel.add(pageBt03);
		pagePanel.add(pageBt06);
		pagePanel.add(pageBt04);
		pagePanel.add(pageBt05);

		JComboBox jb = getScriptComboBox();
		ComboPanel.add(jb);

		buttonPanel.add(southPanel04);



		centerPanel.add(exportCatalog);
		centerPanel.add(ComboPanel);
		centerPanel.add(buttonPanel);
		centerPanel.add(northPanel);
		centerPanel.add(toolPanel);
		centerPanel.add(menuPanel);
		centerPanel.add(setupClickPanel);
		centerPanel.add(clickEXPanel);

		centerPanel.add(alarmPanel);
		centerPanel.add(systemPanel);
		centerPanel.setOpaque(false);
		backPanel01.add(centerPanel);
		basePanel.add(pagePanel);

		basePanel.add(backPanel01);
		pageList.add(backPanel01);

		showMenuPage(null);
		//注意路径问题  / 表示 从根开始
		String imgPath = NativeCp.getOneDriveDir() + "/code/saber_dark.png";
        intIconBar(imgPath);
		this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		this.add(basePanel);
		this.setTitle("MyWind");
		Toolkit.getDefaultToolkit();
		Dimension dm = Toolkit.getDefaultToolkit().getScreenSize();
		this.setSize(335, 518);
		this.setLocation(dm.width-335-5, dm.height-518-50);
		this.setResizable(false);
		this.setAlwaysOnTop(true);
	}
	private JComboBox getScriptComboBox(){
		JComboBox jb = new JComboBox();
		addItemsFromFile(jb);
		jb.setUI(new MyComboBoxUI());
		jb.setRenderer(new MyListCellRenderer());
		jb.setEnabled(true);
		jb.addPopupMenuListener(new PopupMenuListener() {
			@Override
			public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
				jb.removeAllItems();
				addItemsFromFile(jb);
			}

			@Override
			public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
				RunningChain rc = ChainUtil.getRunningChain();
				rc.setAutoChainName(jb.getSelectedItem().toString());
				Map<String, String> map = new HashMap<>();
				String stname = jb.getSelectedItem().toString();
//				stname = stname.substring(0,stname.indexOf("."));
				map.put("STName",stname);
				PropertiesUtil.setValueForStrategy(map);
			}

			@Override
			public void popupMenuCanceled(PopupMenuEvent e) {
			}
		});
		return jb;
	}
	private void addItemsFromFile(JComboBox jb){
		RunningChain rc = ChainUtil.getRunningChain();
		String StategyName = PropertiesUtil.getValueFromStrategyFile("STName");
		String filepath = NativeCp.getUserDir() + "/config/"+ Constant.FGO + "/" + Constant.STRATEGY;
		File file = new File(filepath);
		if (file.exists() ){
			File[] files =  file.listFiles();
			int size = files.length;
			File tempFile;
			int j = 0;
			for (int i = 0; i < size; i++) {
				tempFile = files[i];
				if (tempFile.isFile()){
					jb.addItem(tempFile.getName());
					if (StategyName!=null && StategyName.equals(tempFile.getName())){
						jb.setSelectedIndex(j);
					}
					j++;
				}
			}
		}else{
			file.mkdirs();
		}

	}
    /**
     * 最小化至托盘
     */
    private void intIconBar(String imgPath) {
        JFrame frame = this;
		try {
			this.setIconImage(ImageIO.read(new File(imgPath)));
		} catch (IOException e) {
		}
        this.setVisible(false);
        if (null == ti) {
            // 隐藏Jframe
            //增加托盘右击菜单
            PopupMenu pop = new PopupMenu();
            MenuItem maxMize = new MenuItem("Max");
            MenuItem exit = new MenuItem("Exit");
            MenuItem miniMize = new MenuItem("Min");
            pop.add(exit);
            pop.add(miniMize);
            ti = new TrayIcon(new ImageIcon(imgPath).getImage(), "MyWind", pop);;
            // 托盘图标
            ti.setImageAutoSize(true);
            // 系统托盘
            SystemTray st = SystemTray.getSystemTray();
            // 鼠标器双击事件
            ti.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount() == 2){
                        super.mouseClicked(e);
                        frame.setVisible(true);
                        frame.setExtendedState(JFrame.NORMAL);
                        frame.toFront();
                    }

                }
            });
            // 按下Exit标签
            exit.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    st.remove(ti);
                    System.exit(0);
                }
            });
            // 按下MiniMize标签
            miniMize.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    frame.setVisible(false);
                }
            });
            // 添加至系统托盘
            try {
                st.add(ti);
            } catch (AWTException e) {
                LOGGER.error(e.getMessage(),e);
            }
        }

    }
	private void showMenuPage(JButton jb){
		setCenterPanelVisible(false);
		pagePanel.setVisible(true);
		if (jb!=null){
			jb.setText("显示背景");
		}
	}
	private void showFrontPage(){
		setCenterPanelVisible(false);
		clickEXPanel.setVisible(false);
		pagePanel.setVisible(false);
		menuPanel.setVisible(true);
	}
	private void showAlarmPage(){
		setCenterPanelVisible(false);
		clickEXPanel.setVisible(false);
		pagePanel.setVisible(false);
		alarmPanel.setVisible(true);
		menuPanel.setVisible(true);
	}
	public void showSystemPage(){
		setCenterPanelVisible(false);
		pagePanel.setVisible(false);
		clickEXPanel.setVisible(false);
		menuPanel.setVisible(true);
		systemPanel.setVisible(true);
	}
	private void showClickExPage(){
		setCenterPanelVisible(false);
		pagePanel.setVisible(false);
		systemPanel.setVisible(false);
		menuPanel.setVisible(true);
		clickEXPanel.setVisible(true);

	}
	private void intBts(){

		bts[0] = new BaseZButton(null, 0, "(小号)材料所有号", JIntellitype.MOD_SHIFT, (int) 'P', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = 3981539681889014623L;

			@Override
			public void runMethod() throws Exception {
				gudazi.trainSamllFgo();
			}
		};
		bts[1] = new BaseZButton(null, 0, "(小号+主号)领取奖励抽免费池", JIntellitype.MOD_SHIFT, (int) 'L', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = 8200576435327725059L;

			@Override
			public void runMethod() throws Exception {
				gudazi.allRewardAndRoll();
			}
		};
		bts[2] = new BaseZButton(null, 0, "(小号+主号)签到所有号", JIntellitype.MOD_SHIFT, (int) 'S', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = 53933841194261802L;

			@Override
			public void runMethod() throws Exception {
				gudazi.signAllFGO();
			}
		};
		bts[3] = new BaseZButton(null, 0, "(小号+主号)执行所有", JIntellitype.MOD_SHIFT, (int) 'T', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = 2069565531679104865L;

			@Override
			public void runMethod() throws Exception {
				gudazi.goAll();
			}
		};
		bts[4] = new BaseZButton(null, 0, "(账号10)开始刷活动(Shift+K)", JIntellitype.MOD_SHIFT, (int) 'K', false, false, BaseZButton.pink) {
			private static final long serialVersionUID = 1369499050729104861L;

			@Override
			public void runMethod() throws Exception {
				gudazi.eventingFgo();
			}
		};
		bts[5] = new BaseZButton(null, 0, "更新FGO", JIntellitype.MOD_SHIFT, (int) 'Q', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = -7555639858773795825L;

			@Override
			public void runMethod() throws Exception {
				gudazi.updateAllFGO(2);
			}
		};
		bts[6] = new BaseZButton(null, 0, "(账号10)无限刷EXP", JIntellitype.MOD_SHIFT, (int) 'P', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730448L;

			@Override
			public void runMethod() throws Exception {
				gudazi.mainAccountEXP40();
			}
		};
		bts[7] = new BaseZButton(null, 0, "开启账号", JIntellitype.MOD_SHIFT, (int) 'O', true, false, BaseZButton.pink) {
			private static final long serialVersionUID = 432750026975346042L;

			@Override
			public void runMethod() throws Exception {
				gudazi.openEvent();
			}
		};

		bts[34] = new BaseZButton(null, 0, "细化战斗(Alt+Z)", JIntellitype.MOD_ALT, (int) 'Z', false, false, BaseZButton.pink) {
			private static final long serialVersionUID = -7389326247723796435L;

			@Override
			public void runMethod() throws Exception {
				gudazi.onlyFightForAll();
			}
		};
		bts[9] = new BaseZButton(null, 0, "自动按键(Alt+X/1)", JIntellitype.MOD_ALT, (int) 'X', false, false, BaseZButton.pink) {
			private static final long serialVersionUID = -1900866258318497377L;

			@Override
			public void runMethod() {
				wuna.alwaysClick();
			}
		};
		bts[25] = new BaseZButton(null, 0, "战斗", JIntellitype.MOD_SHIFT, (int) 'i', true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;

			@Override
			public void runMethod() {
				this.selectIfRestart();
			}
		};
		bts[26] = new BaseZButton(null, 0, "终止", JIntellitype.MOD_ALT, KeyEvent.VK_0, true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;

			@Override
			public void runMethod() {
				GameUtil.shutDownALl();
			}
		};
		bts[27] = commonModules.getPauseBtn();
		bts[28] = new BaseZButton(null, 0, "超时", JIntellitype.MOD_SHIFT, (int) 'i', true, true, BaseZButton.pink) {
			private static final long serialVersionUID = -7491221341872701498L;

			@Override
			public void runMethod() {
				GameUtil.setFORCE_OUTTIME(true);
				wuna.setGO(false);
			}
		};

		bts[29] = new BaseZButton(null, 0, "点击设置", JIntellitype.MOD_ALT, KeyEvent.VK_1, false, false, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730448L;

			@Override
			public void runMethod() {
				wuna.configClick(this);
			}
		};
		bts[30] = new BaseZButton(null, 0, "清空", JIntellitype.MOD_SHIFT, (int) 'P', true, true, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730448L;

			@Override
			public void runMethod() {
				wuna.falshClick(this);
			}
		};
		bts[31] = new BaseZButton(null, 0, "解除激活", JIntellitype.MOD_SHIFT, (int) 'P', true, true, BaseZButton.pink) {
			private static final long serialVersionUID = 6504858991507730448L;

			@Override
			public void runMethod() {
				deActiveAll(centerPanel);
			}
		};
		bts[32] = commonModules.getMoveToXYBt();
		bts[33] = commonModules.getXYBt();
		int len  = bts.length;
		for (int i = 0; i < len; i++) {
			if(null != bts[i]){
				btsMaps.put(bts[i].getText(),bts[i]);
			}

		}

	}
	private void setCenterPanelVisible(boolean flag){
		Component[] comps = centerPanel.getComponents();
		for (int i = 0; i < comps.length; i++) {
			comps[i].setVisible(flag);
		}
	}
	private void hideWithOutText(String[] text,Zpanel zp,boolean flag){
		Component[] comps = zp.getComponents();
		Component temp;
		JButton zt;
		for (int i = 0; i < comps.length; i++) {
			temp = comps[i];
			if (temp instanceof Zpanel ) {
				hideWithOutText(text, (Zpanel)temp, flag);
			}else if (temp instanceof JButton){
				zt = (JButton) temp;
				int size = text.length;
				int count = 0;
				String tempText;
				for (int j = 0; j < size; j++) {
					tempText = text[j];
					if (zt.getText().contains(tempText)){
						count++;
					}
				}
				if (count>0){
					System.out.println(zt.getText());
					zt.setVisible(true);
				}else{
					if (zt.isVisible()){
						cpList.add(zt);
					}
					zt.setVisible(flag);
				}
			}else if (temp instanceof ZTextField || temp instanceof ZLable || temp instanceof JComboBox){
				if (temp.isVisible()){
					cpList.add(temp);
				}
				temp.setVisible(flag);
			}else{
				temp.setVisible(flag);
			}
		}
	}
	public static int getAccount() {
		String openAccountStr = PropertiesUtil.getValueFromOpenFile("openAccount");
		return Integer.valueOf(openAccountStr);
	}

	private void addSouthPanle04(BaseZButton jbTemp) {
		jbTemp.setAllowRepeat(true);
		JIntellitype.getInstance().registerHotKey(jbTemp.getMarkCode(), jbTemp.getShortcunt01(), jbTemp.getShortcunt02());
		southPanel04.add(jbTemp);
	}
	private void showBackGround(JButton bt) {
		if (bt.getText().contains("显示背景")){
			String[] texts = {"背景","菜单","解除"};
			hideWithOutText(texts, centerPanel, false);
			bt.setText("显示按钮");
			menuPanel.setVisible(true);
		} else {
			showBackGroundInner(bt);
		}
	}
	private void showBackGroundInner(JButton bt){
		int size = cpList.size();
		Component temp;
		for (int i = 0; i < size; i++) {
			temp = cpList.get(i);
			temp.setVisible(true);
		}
		cpList= new ArrayList<>();
		bt.setText("显示背景");
	}
	public void changeBackGround() {
		backPanel01.setBackground(GameUtil.getBackGroundPreFix((int)(333*1.1), (int)(470*1.1)));
	}
	public void changeBackGroundByPath(String path) {
	    File file = new File(path);
	    if (file.exists()) {
            backPanel01.setBackground(GameUtil.getBackGroundPreFix((int)(333*1.1), (int)(470*1.1),path));
        }
	}


	public BaseZButton[] getBts() {
		return bts;
	}

    public TrayIcon getTi(String imgPath, PopupMenu pop) {
        return ti;
    }

    private void deActiveAll(Zpanel zp){
		Component[] comps = zp.getComponents();
		Component temp;
		BaseZButton zt;
		String textTemp;
		for (int i = 0; i < comps.length; i++) {
			temp = comps[i];
			if (temp instanceof Zpanel ) {
				deActiveAll((Zpanel)temp);
			}else if (temp instanceof BaseZButton){
				zt = (BaseZButton) temp;
				if (zt.getText().contains("(已激活)")){
					JIntellitype.getInstance().unregisterHotKey(zt.getMarkCode());
					zt.setEnabled(true);
					textTemp = zt.getText();
					zt.setText(textTemp.replace(" (已激活)", ""));
				}else{
				}
			}else{
			}
		}
	}
}
